using UnityEngine;

public static class CharacterAnimationUtility
{
    private static readonly Bijection<ECharacterMotion, int> MotionAndId;
    private static readonly Bijection<EDirection, int> FaceAndParameter;
    private static readonly CharacterAnimatorData data;

    static CharacterAnimationUtility()
    {
        data = Resources.Load<CharacterAnimatorData>("CharacterAnimatorData");
        MotionAndId = new Bijection<ECharacterMotion, int>();
        FaceAndParameter = new Bijection<EDirection, int>();
        for (int i = 0; i < data.motionNames.Length; i++)
        {
            MotionAndId.Add((ECharacterMotion)i, Animator.StringToHash(data.motionNames[i]));
        }
        for (int i = 0; i < data.faces.Length; i++)
        {
            FaceAndParameter.Add(data.faces[i], i);
        }
    }

    public static int ToFaceParameter(EDirection e)
        => FaceAndParameter[e];
    public static EDirection ToFace(int parameter)
        => FaceAndParameter[parameter];

    public static int ToMotionId(ECharacterMotion e)
        => MotionAndId[e];
    public static ECharacterMotion ToMotion(int id)
        => MotionAndId[id];
}
